home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 283_01 / scroll.c < prev    next >
C/C++ Source or Header  |  1988-12-14  |  3KB  |  93 lines

  1. /* scroll.c -- 9/5/88, 12/9/88, d.c.oshel
  2.    */
  3.  
  4. #include "vidinit.h"
  5.  
  6.  
  7. /* Scroll functions honor the current window, and do not alter global
  8. ** col & row settings.  The window scrolls up or down one line at a time.
  9. **
  10. ** NOTICE:   The fresh, blank line which results from scrolling should
  11. **           normally have the CURRENT video attribute, vid_attr.
  12. **           If scrolling is caused by wputs(), this might mean that 
  13. **           the "current" video attribute is whatever wputs() last found
  14. **           as an attribute escape command, e.g. "^1", whereas the
  15. **           window itself should be normal or reversed, etc.
  16. **
  17. **           You can explicitly request a scrolling attribute by setting
  18. **           ScrollAttributeFlag to a vid array index, plus 1 to make
  19. **           the flag non-zero.
  20. **
  21. **           For example, ScrollAttributeFlag <-- 3
  22. **                        2 <-- index <-- (ScrollAttributeFlag-1)
  23. **                        attr <-- vid[2] <-- vid[index]
  24. **
  25. **           However, if  ScrollAttributeFlag == 0
  26. **                        attr <-- vid_attr, whatever is current
  27. **
  28. **           WindowBox() automatically sets this flag when a window
  29. **           is created.  Restorescreen() resets it to use vid_attr.
  30. */
  31.  
  32. int ScrollAttributeFlag = 0;
  33. static char errmsg[] = "\a\nCIAO: scroll: out of memory\n";
  34.  
  35. void scrolldn( void )  /* scroll current window down one line */ 
  36. {
  37.     int far *buffer;
  38.     int i,j,num;
  39.     int va;
  40.  
  41.     num = rm-lm+1;  /* number of columns in current window */
  42.  
  43.     buffer = (int far *) _fmalloc( (num * sizeof(int)) + 4 );
  44.     if ( buffer == (int far *) NULL )
  45.     {
  46.         printf( errmsg );
  47.         exit (39);
  48.     }
  49.  
  50.     for ( i = bm, j = bm - 1; i > tm; i--,j-- )  
  51.     {
  52.         MSJ_MovScrBuf( (char far *) buffer, j, lm, num, &video );
  53.         MSJ_MovBufScr( (char far *) buffer, i, lm, num, &video );
  54.     }
  55.  
  56.     /* went down, so clear top line */
  57.     va = ScrollAttributeFlag ? vid[ScrollAttributeFlag-1] : vid_attr;
  58.     MSJ_SetFldAttr( SPC, tm, lm, va, num, &video );
  59.  
  60.     _ffree(buffer);
  61. }
  62.  
  63.  
  64. void scrollup( void )  /* scroll current window up one line */
  65. {
  66.     int far *buffer;
  67.     int i, j, num;
  68.     int va;
  69.  
  70.     num = rm-lm+1;  /* number of columns in current window */
  71.  
  72.     buffer = (int far *) _fmalloc( (num * sizeof(int)) + 4 );
  73.     if ( buffer == (int far *) NULL )
  74.     {
  75.         printf( errmsg );
  76.         exit (40);
  77.     }
  78.     
  79.     for ( i = tm, j = tm + 1; i < bm; i++,j++ )  
  80.     {
  81.         MSJ_MovScrBuf( (char far *) buffer, j, lm, num, &video );
  82.         MSJ_MovBufScr( (char far *) buffer, i, lm, num, &video );
  83.     }
  84.  
  85.     /* went up, so clear bottom line */
  86.     va = ScrollAttributeFlag ? vid[ScrollAttributeFlag-1] : vid_attr;
  87.     MSJ_SetFldAttr( SPC, bm, lm, va, num, &video );
  88.  
  89.     _ffree(buffer);
  90. }
  91.  
  92.  
  93.